﻿using AwesomeChromeFormUI.Attributes;
using AwesomeChromeFormUI.Configs;
using AwesomeChromeFormUI.Reflections;
using System;
using System.Reflection;

namespace AwesomeChromeFormUI.Interfaces.Configs
{
    /// <summary>
    /// 默认实现
    /// </summary>
    public class DefaultIBrowserConfiger 
    {
        public static BrowserConfiguration CreateCustomBrowserConfiguration()
        {
            Type type = AttributeUtil.FindFirstAnnotatedClass<BrowserConfigurationAttribute, IBrowserConfiger>();

            if (type != null)
            {
                ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);

                if (constructor != null)
                {
                    IBrowserConfiger browserConfiger = constructor.Invoke(null) as IBrowserConfiger;
                    return browserConfiger.CreateCustomBrowserConfiguration();
                }

            }
            
            return new BrowserConfiguration();
        }
    }
}
